package tree;

/**
 * @author way
 * @create 2025-02-10 17:35
 */
public class _101_isSymmetric {
    public boolean isSymmetric(TreeNode root) {
        if (root == null) return false;

        return compare(root.left, root.right);
    }

    private boolean compare(TreeNode left, TreeNode right) {
        if (left == null && right != null) return false;
        else if (left != null && right == null) return false;
        else if (left == null && right == null) return true;
        else if (left.val != right.val) return false;

        boolean outside = compare(left.left, right.right);
        boolean inside = compare(left.right, right.left);
        return outside && inside;
    }
}
